//
//  WHRootNavigationController.m
//  BinFengExpressOwner
//
//  Created by 邓伟浩 on 2018/10/13.
//  Copyright © 2018年 BinFeng. All rights reserved.
//

#import "WHRootNavigationController.h"
#import "WHRootViewController.h"

@interface WHRootNavigationController ()<UINavigationControllerDelegate>

@end

@implementation WHRootNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.delegate = self;
    self.interactivePopGestureRecognizer.delegate = (id)self;
    
}

+ (void)initialize {
    UINavigationBar *navBar = [UINavigationBar appearance];
    [navBar setBarTintColor:CViewBgMainColor];

    [navBar setTintColor:KBlackColor];
    [navBar setTitleTextAttributes:@{NSForegroundColorAttributeName:CFontTitleBlackColor,
                                     NSFontAttributeName:BOLDSYSTEMFONT(18)}];
    
//    [navBar setBackgroundImage:[UIImage new] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
}

/** push时隐藏tabbar */
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if (self.viewControllers.count > 0) {
        viewController.hidesBottomBarWhenPushed = YES;
    }
    [super pushViewController:viewController animated:animated];
}

- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
//  禁用左滑返回
//    if (self.viewControllers.count == 2) {
//        self.interactivePopGestureRecognizer.enabled = NO;
//    } else {
//        self.interactivePopGestureRecognizer.enabled = YES;
//    }
}

/** 是否隐藏导航栏 */
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    
    if ([viewController isKindOfClass:[WHRootViewController class]]) {
        WHRootViewController *vc = (WHRootViewController *)viewController;
        
        if (vc.isHidenNaviBar) {
            vc.view.top = 0;
            [vc.navigationController setNavigationBarHidden:YES animated:animated];
        } else {
            vc.view.top = kTopHeight;
            [vc.navigationController setNavigationBarHidden:NO animated:animated];
        }
    }
    
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    UIViewController *topVC = self.topViewController;
    return [topVC preferredStatusBarStyle];
}

@end
